﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace DELVE_GAME.ViewStructure.MapEditor
{
    class MapEditorCell : Actor
    {
        Tile myTile;
        bool isSelected;
        Color myBackgroundColor;
        Map map;

        public MapEditorCell(Tile tile, int x, int y, Sprite tilesSprite, int offsetX, int offsetY, Map map)
        {
            this.myTile = tile;
            this.x = x;
            this.y = y;
            this.sprite = tilesSprite;
            this.width = 20;
            this.height = 20;
            offsetX = 15;
            offsetY = 15;
            myBackgroundColor = Color.Black;
            this.offsetX = offsetX;
            this.offsetY = offsetY;
            this.map = map;
        }

        public void setSelected(bool selected)
        {
            this.isSelected = selected;
        }

        public int getOffsetX()
        {
            return offsetX;
        }

        public int getOffsetY()
        {
            return offsetY;
        }

        public override void draw(Microsoft.Xna.Framework.Graphics.SpriteBatch sb)
        {
            Color drawBGColor;
            switch (map.getStartingAreaPlayer(this.myTile))
            {
                case 0:
                    myBackgroundColor = Color.Yellow;
                    break;
                case 1:
                    myBackgroundColor = Color.Purple;
                    break;
                case 2:
                    myBackgroundColor = Color.Blue;
                    break;
                case 3:
                    myBackgroundColor = Color.Green;
                    break;
                default :
                    drawBGColor = Color.Black;
                    break;
            }
            if (map.isInGroup(this.myTile))
            {
                myBackgroundColor = Color.Red;
            }
            if (isSelected) { drawBGColor = Color.Cornsilk; }
            else { drawBGColor = myBackgroundColor; }

            sprite.draw(sb, this.x * width + offsetX - 1, this.y * height + offsetY - 1, 0, ((double)this.width / sprite.width()), drawBGColor);

            int tileTypeOffset = myTile.type;// *9;//imageIndex * 9;//(int)TILE_VARIANTS.NUM_TYPES; 
            int xPos = x * this.width  + offsetX;/////////////////////////////////////////////////////////////////////////////
            int yPos = y * this.height + offsetY;/////////////////////////////////////////////////////////////////////////////
            double spriteWidth = ((double)this.width - (2)) / sprite.width();
            Color color = Color.LightGray;
            sprite.draw(sb, xPos, yPos, /*(int)TILE_VARIANTS.NUM_TYPES +*/ tileTypeOffset, spriteWidth, color);
        }

        public Tile getTile()
        {
            return myTile;
        }
    }
}
